package paywithdrawlogic

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/withdraw"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type WithdrawTypeUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewWithdrawTypeUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WithdrawTypeUpdateLogic {
	return &WithdrawTypeUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *WithdrawTypeUpdateLogic) WithdrawTypeUpdate(in *rpc.UpdateWithDrawTypeRequest) (*rpc.UpdateWithDrawTypeResponse, error) {
	if in.WithDrawType.FeeRate >= 1 {
		return nil, xerrors.ErrWithdrawFeeErr
	}
	m := withdraw.NewTypeModel(l.ctx, l.svcCtx)
	return m.WithdrawTypeUpdate(in)
}
